<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <div>
            {{arr}}
            <button @click="arrFn">修改arr</button>
        </div>
        <div>
            {{user}}
            <button @click="objectFn">修改arr</button>
        </div>
    </div>
</body>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            arr: [1, 2, 3],
            user: { a: 1 }
        },
        methods: {
            arrFn() {
                this.arr[1] = 999
                this.arr[3] = 123
                // set(要修改的数组,修改的索引下标,修改的值)
                // this.$set(this.arr, 1, 99)
                console.log(this.arr);
            },

            objectFn() {
                // this.user.a = 999
                // this.user.b = 555
                console.log(this.user);
                // set(要修改的数组,修改的属性,修改的值)
                this.$set(this.user, "b", 555)
            },
        }
    })
</script>

</html>